

#ifndef NRF24L01_H_
#define NRF24L01_H_

#ifndef bool
#define bool unsigned char
#endif
#ifndef false
#define false 0
#endif
#ifndef true
#define true !false
#endif

// Data and control registers
#define NORDIC_R_REGISTER 0x00
#define NORDIC_W_REGISTER 0x20
#define NORDIC_R_RX_PAYLOAD 0x61
#define NORDIC_W_TX_PAYLOAD 0xA0
#define NORDIC_FLUSH_TX 0xE1
#define NORDIC_FLUSH_RX 0xE2
#define NORDIC_REUSE_TX_PL 0xE3
#define NORDIC_R_RX_PL_WID 0x60
#define NORDIC_W_ACK_PAYLOAD 0xA8
#define NORDIC_W_TX_PAYLOAD_NOACK 0xB0
#define NORDIC_NOP 0xFF

//Register Map
#define NORDIC_CONFIG 0x00
#define NORDIC_EN_AA 0x01
#define NORDIC_EN_RXADDR 0x02
#define NORDIC_SETUP_AW 0x03
#define NORDIC_SETUP_RETR 0x04
#define NORDIC_RF_CH 0x05
#define NORDIC_RF_SETUP 0x06
#define NORDIC_STATUS 0x07
#define NORDIC_OBSERVE_TX 0x08
#define NORDIC_RPD 0x09
#define NORDIC_RX_ADDR_P0 0x0A
#define NORDIC_RX_ADDR_P1 0x0B
#define NORDIC_RX_ADDR_P2 0x0C
#define NORDIC_RX_ADDR_P3 0x0D
#define NORDIC_RX_ADDR_P4 0x0E
#define NORDIC_RX_ADDR_P5 0x0F
#define NORDIC_TX_ADDR 0x10
#define NORDIC_RX_PW_P0 0x11
#define NORDIC_RX_PW_P1 0x12
#define NORDIC_RX_PW_P2 0x13
#define NORDIC_RX_PW_P3 0x14
#define NORDIC_RX_PW_P4 0x15
#define NORDIC_RX_PW_P5 0x16
#define NORDIC_FIFO_STATUS 0x17
#define NORDIC_DYNPD 0x1C



#include "delays.h"
#include "spi.h"
#include "uart.h"
#include "msp430G2553.h"                        // device specific header


void Nordic_Init(unsigned char RX);
void Nordic_InitDefault(unsigned char RX);
void Nordic_ChipEnable();
void Nordic_ChipDisable();
void Nordic_Transmit();
unsigned char Nordic_ReadCommand(unsigned char Data); //Remove from header after debug
void Nordic_WriteCommand(unsigned char Address, unsigned char Data); //Remove from header after debug
unsigned char Nordic_read_rx_payload(unsigned char * data, unsigned int len);
unsigned char Nordic_ReadPayloadWidth();
void Nordic_WritePayload(unsigned char* Data, unsigned int len);
void Nordic_ReadPayload(unsigned char* Data);

void Nordic_FlushTx();
void Nordic_FlushRx();
void Nordic_ReuseTxPL();
unsigned char Nordic_write_tx_payload(unsigned char * data, unsigned int len, bool transmit);
void Nordic_NoOperation();
unsigned char Nordic_GetConfig();
void Nordic_CRC16();
void Nordic_PowerUp();
void Nordic_PowerDown();
void Nordic_RxMode();
void Nordic_TxMode();
void Nordic_EnableAA(unsigned char Data);
void Nordic_SetAddressWidth(unsigned char Width);
void Nordic_SetRFChannel(unsigned char Channel);
unsigned char Nordic_GetRFChannel();
void Nordic_SetRFSetup(unsigned char Data);
unsigned char Nordic_GetStatus();
void Nordic_ClearInterrupts();

unsigned char Nordic_IRQ();
unsigned char Nordic_IrqRx();
unsigned char Nordic_IrqTx();
unsigned char Nordic_IrqMaxRT();

void Nordic_RxAddress(unsigned char Channel, unsigned char Length, unsigned long Address);
void Nordic_getRxAddress(unsigned char Channel);
void Nordic_SetRxChannel0(unsigned char* Address);//TEMPORARY FUNCTION
void Nordic_SetRxChannel1(unsigned char* Address);//TEMPORARY FUNCTION
void Nordic_SetTxChannel(unsigned char* Address);
void Nordic_RxPayloadLength(unsigned char Channel, unsigned char Width);
unsigned char Nordic_GetFIFOStatus();
unsigned char Nordic_GetStatus_TXReuse();
unsigned char Nordic_GetStatus_TXFull();
unsigned char Nordic_GetStatus_TXEmpty();
unsigned char Nordic_GetStatus_RXFull();
unsigned char Nordic_GetStatus_RXEmpty();
void Nordic_csh(void);
void Nordic_csl(void);


void Nordic_ReadRegisters(unsigned char Address, unsigned char * data, unsigned int len);


#endif /*NRF24L01_H_*/
